﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mvc.XForms.Actions;

namespace Mvc.XForms.Controls.Settings {
	public class RepeatSettings<TContext> {
		public IRepeat<TContext> Repeat { get; private set; }

		public RepeatSettings(IRepeat<TContext> repeat) {
			Repeat = repeat;
		}

		public void ItemTemplate(Action<IRepeat<TContext>> itemTemplate) {
			Repeat.ItemTemplateAction = itemTemplate;
			Repeat.Render();
		}

		public RepeatSettings<TContext> Label(string label) {
			throw new NotImplementedException();
		}

		public RepeatSettings<TContext> ItemTag(string itemTag) {
			Repeat.ItemTag = itemTag;
			return this;
		}

		public RepeatSettings<TContext> Tag(string tag) {
			Repeat.Tag = tag;
			return this;
		}

		public RepeatSettings<TContext> DefaultItem(TContext defaultItem) {
			Repeat.DefaultItem = defaultItem;
			return this;
		}

		public RepeatSettings<TContext> Relevant(bool relevant) {
			Repeat.Relevant = relevant;
			return this;
		}

		public RepeatSettings<TContext> CssClass(string cssClass) {
			Repeat.CssClass.Add(cssClass);
			return this;
		}

		public RepeatSettings<TContext> Action(XFormEvent xformsEvent, string scriptFunction) {
			var action = new ActionAction() {
				Event = xformsEvent,
				JSFunction = scriptFunction
			};
			Repeat.Actions.Add(action);
			return this;
		}
	}
}
